<template>
  <div class="main bill-detail">
    <el-form :model="form" ref="form" label-width="80px" :inline="true">
      <el-form-item label="SKU">
        <el-input v-model="form.sku" placeholder="SKU"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSearch()">搜索</el-button>
      </el-form-item>
    </el-form>
    <section>
      <el-table v-loading="loading" :data="list" border style="width: 100%">
        <el-table-column align="center" prop="periodTime" label="账期" width="100"></el-table-column>
        <el-table-column align="center" prop="addTime" label="下单时间" width="100"></el-table-column>
        <el-table-column align="center" prop="payTime" label="支付时间" width="100"></el-table-column>
        <el-table-column align="center" prop="shippingTimeFh" label="发货时间" width="100"></el-table-column>
        <el-table-column prop="originalOrderNo" label="订单号" min-width="210"></el-table-column>
        <el-table-column prop="payName" label="支付方式" width="100"></el-table-column>
        <el-table-column prop="orderStatus" label="订单状态" width="100"></el-table-column>
        <el-table-column prop="shippingStatus" label="发货状态" width="100"></el-table-column>
        <el-table-column prop="merchantName" label="供应商名称" width="180"></el-table-column>
        <el-table-column prop="category_name" label="商品大类" width="100"></el-table-column>
        <el-table-column prop="middle_name" label="商品中类" width="100"></el-table-column>
        <el-table-column prop="small_name" label="商品小类" width="100"></el-table-column>
        <el-table-column prop="goodsSn" label="款号"></el-table-column>
        <el-table-column prop="sku" label="SKU"></el-table-column>
        <el-table-column prop="goodsName" label="商品名称"></el-table-column>
        <el-table-column prop="goodsNumber" label="数量"></el-table-column>
        <el-table-column prop="costPrice" label="商品成本价"></el-table-column>
        <el-table-column prop="settlementAmount" label="结算金额"></el-table-column>
        <el-table-column prop="productManager" label="产品经理"></el-table-column>
        <el-table-column prop="sourceType" label="来源"></el-table-column>
        <el-table-column prop="sourceId" label="来源标识"></el-table-column>
        <el-table-column prop="payState" label="参与本账期单结算"></el-table-column>
      </el-table>
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="form.pageNum"
        :page-size="form.pageSize"
        layout="total, prev, pager, next"
        :total="pageTotal"
      ></el-pagination>
    </section>
  </div>
</template>
<script>
export default {
  name: "billDetail",
  props: {
    id: {
      default: ""
    }
  },
  data() {
    return {
      form: {
        sku: "",
        pageNum: 1,
        pageSize: 10
      },
      list: [],
      pageTotal: 0,
      loading: true
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    onSearch() {
      this.getData();
    },
    getData() {
      this.loading = true;
      this.form.id = `${this.id}`;
      this.request({
        url: "/finance/billDetail/list",
        method: "post",
        data: this.form
      }).then(res => {
        if (res.status == 200) {
          this.list = res.data.rows;
          this.pageTotal = res.data.total;
          this.list.forEach((item, index) => {
            this.list[index].orderStatus = this.getGoodsStat(
              this.list[index].orderStatus
            );
            this.list[index].shippingStatus = this.shippingStat(
              this.list[index].shippingStatus
            );
            this.list[index].sourceType = this.source(
              this.list[index].sourceType
            );
            this.list[index].payState =
              this.list[index].payState == 0
                ? "不参与本期结算"
                : "参与本期结算";
          });
          this.loading = false;
          /* for(let i=0;i<this.list.length;i++){
              this.list[i].periodTime = this.list[i].periodTime.split('-')[0]+'-'+this.list[i].periodTime.split('-')[1];
            } */
        }
      });
    },
    getGoodsStat(val) {
      switch (val) {
        case 0:
          return "未确认";
        case 1:
          return "已确认";
        case 2:
          return "待发货";
        case 3:
          return "已作废";
        case 4:
          return "已收货";
        case 5:
          return "已完成";
        case 6:
          return "付款异常";
        case 7:
          return "超时取消";
        case 8:
          return "已退款";
        default:
          return "";
      }
    },
    shippingStat(val) {
      switch (val) {
        case 0:
          return "初始";
        case 1:
          return "预分配缺货处理中";
        case 2:
          return "已完成预分配";
        case 3:
          return "已通知配货";
        case 4:
          return "拣货中";
        case 5:
          return "已完成拣货";
        case 6:
          return "发货";
        case 7:
          return "已出库";
        case 9:
          return "取消";
        default:
          return "";
      }
    },
    source(val) {
      switch (val) {
        case 2:
          return "销售出库";
        case 4:
          return "销售退货";
        case 8:
          return "手工添加";
        default:
          return "";
      }
    },
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getData();
    }
  }
};
</script>
